% line_cnt = 8
% print_hdr = true
%
% ## Hash Autovivification
% l = ->(h, k) { h[k] = Hash.new(&l) }
% eset_eqns = Hash.new(&l)
% eset_eqns_print = Hash.new(&l)
%
% @es_sheet_pins.each do |grp|
%   if Origen.top_level.has_pin?(grp)
%     pin_ary = get_pin_objects(grp)
%     pin_ary.each do |next_pin|
%       pin_nam = Origen.top_level.pin(next_pin.id).name
%       found_pin_eqn = false
%       @es.keys.each do |eset|
%         if @es[eset].pins.key?(pin_nam)
%           eset_eqns[grp][eset][pin_nam] = @es[eset].pins[pin_nam]
%           eset_eqns_print[grp][pin_nam][eset] = @es[eset].pins[pin_nam]
%           found_pin_eqn = true
%         end
%       end
%       unless found_pin_eqn
%         Origen.log.error "GRP #{grp}, PIN #{pin_nam}:  Pin timing is not defined in any edgesets"
%         next
%       end
%     end
%   else
%     Origen.log.error "Undefined pin/pingroup in pattern header (#{grp})"
%   end
% end
%
% eset_eqns.keys.each do |grp|
%   grp_edge_same = true
%   eset_eqns[grp].keys.each do |eset_key|
%     grp_edge = nil
%     pin_ary = get_pin_objects(grp)
%     pin_ary.each do |next_pin|
%       pin_nam = Origen.top_level.pin(next_pin.id).name
%       if eset_eqns[grp][eset_key].key?(pin_nam)
%         if grp_edge.nil?
%           grp_edge = eset_eqns[grp][eset_key][pin_nam]
%         elsif !edges_eql?(grp_edge, eset_eqns[grp][eset_key][pin_nam])
%           grp_edge_same = false
%         end
%       else
%         grp_edge_same = false
%       end
%     end
%   end
%
%   pin_grp_done = false
%   eset_eqns_print[grp].keys.each do |pin_nam|
%     pin_grp_done ? break : nil
%     eset_eqns_print[grp][pin_nam].keys.each do |eset|
%       data_src  = @es[eset].pins[pin_nam].d_src
%       data_fmt  = @es[eset].pins[pin_nam].d_fmt
%       drv_on    = @es[eset].pins[pin_nam].d0_edge
%       drv_data  = @es[eset].pins[pin_nam].d1_edge
%       drv_ret   = @es[eset].pins[pin_nam].d2_edge
%       drv_off   = @es[eset].pins[pin_nam].d3_edge
%       cmp_mode  = @es[eset].pins[pin_nam].c_mode
%       cmp_open  = @es[eset].pins[pin_nam].c1_edge
%       cmp_close = @es[eset].pins[pin_nam].c2_edge
%       tim_res   = @es[eset].pins[pin_nam].t_res
%       clk_per   = @es[eset].pins[pin_nam].clk_per
%       drv_on    = format_uflex_edge(drv_on, line_cnt)
%       drv_data  = format_uflex_edge(drv_data, line_cnt)
%       drv_ret   = format_uflex_edge(drv_ret, line_cnt)
%       drv_off   = format_uflex_edge(drv_off, line_cnt)
%       cmp_open  = format_uflex_edge(cmp_open, line_cnt)
%       cmp_close = format_uflex_edge(cmp_close, line_cnt)
%       clk_per   = format_uflex_edge(clk_per, line_cnt)
%       if print_hdr
%         print_hdr = false
%         tim_mode  = @es[eset].t_mode
<%= "DTEdgesetSheet,version=2.3:platform=Jaguar:toprow=-1:leftcol=-1:rightcol=-1\tEdge Sets" %>
<%= "" %>
<%= "\tTiming Mode:\t#{tim_mode}" %>
<%= "\tTime Domain:\t\t\t\tStrobe Ref Setup Name:" %>
<%= "" %>
<%= "\t\t\tData\t\tDrive\t\t\t\tCompare\t\t\t\tEdge Resolution" %>
<%= "\tPin/Group\tEdge Set\tSrc\tFmt\tOn\tData\tReturn\tOff\tMode\tOpen\tClose\tRef Offset\tMode\tComment" %>
%       end
%       if grp_edge_same
<%= "\t#{grp}\t#{eset}\t#{data_src}\t#{data_fmt}\t#{drv_on}\t#{drv_data}\t#{drv_ret}\t#{drv_off}\t#{cmp_mode}\t#{cmp_open}\t#{cmp_close}\t\t#{tim_res}" %>
%         line_cnt += 1
%         pin_grp_done = true
%       else
<%= "\t#{pin_nam}\t#{eset}\t#{data_src}\t#{data_fmt}\t#{drv_on}\t#{drv_data}\t#{drv_ret}\t#{drv_off}\t#{cmp_mode}\t#{cmp_open}\t#{cmp_close}\t\t#{tim_res}" %>
%         line_cnt += 1
%       end
%     end
%   end
% end
%